<template>
  <a-config-provider :locale="locale == 'en' ? enUS : zhCN">
    <router-view #="{ Component }">
      <component :is="Component" />
    </router-view>
  </a-config-provider>
</template>
<script lang="ts" setup>
import { useLocale } from '@/locales/useLocale';
import { onMounted, watch, onUnmounted, nextTick, ref } from 'vue';
import { useUserStore } from "@/store/modules/user";
import { useDynamicRouting } from "@/store/modules/dynamicRouting";
import router from '@/router';
import { useRoute, useRouter } from "vue-router";
import { Storage } from "@/utils/Storage";
import { SET_SETTING_System_Icon, SET_SETTING_System_Title } from '@/utils/common';
import enUS from 'ant-design-vue/es/locale/en_US';
import zhCN from 'ant-design-vue/es/locale/zh_CN';
import dayjs from 'dayjs';
import 'dayjs/locale/zh-cn';
dayjs.locale('zh-cn');
const dynamicRouting = useDynamicRouting();
const userStore = useUserStore();
const { getAntdLocale, } = useLocale();

const locale = ref('CN');
const route = useRoute();
onMounted(() => {
  window.addEventListener('beforeunload', e => {
    Storage.set("isLogin", false);
    Storage.set('selectFullPath', route.path,);
    Storage.set('selectPathQuery', route.query,);
    Storage.set('selectMenuPath', route.path,);
  })
  //getRoutes();
  if (sessionStorage.getItem('user')) {
    SET_SETTING_System_Icon(JSON.parse(sessionStorage.getItem('user') || '')?.userInfo?.tabPic);
    SET_SETTING_System_Title(JSON.parse(sessionStorage.getItem('user') || '')?.userInfo?.pageTitleSetting);
  }
})
// watch
watch(() => getAntdLocale.value, (newVal, oldVal) => {
  if (newVal.locale == 'en') {
    locale.value = 'en';
  } else {
    locale.value = 'CN';
  }
}, { deep: true })
</script>

<style >
html {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
}

/* ::-webkit-scrollbar {
    display: none;
  } */

* {
  margin: 0;
}
</style>
